package com.itheima.servlet;

import com.itheima.pojo.Category;
import com.itheima.service.CategoryService;
import com.itheima.service.impl.CategoryServiceImpl;
import com.itheima.utils.Result;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author ZhangYan
 * @Date 2021/1/15
 */
@WebServlet("/category")
public class CategoryServlet extends BaseServlet{

    private CategoryService categoryService = new CategoryServiceImpl();

    //查询所有方法
    public void findAll(HttpServletRequest request, HttpServletResponse response) throws Exception{
        //调用service层方法
        List<Category> list = categoryService.findAll();
        //判断是否查询导数据
        if (list != null){
            //查询成功 响应给前端
            //把信息封装到Result对象中
            //调用Base公共方法,把result对象转换成json格式 响应回去
            printResult(Result.SUCCESS,"查询成功",list,response);
        } else {
            //没有数据
            printResult(Result.FAILS,"查询失败...",response);
        }
    }
}
